package coml.allen.api.ttl;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @author sesshomaru
 * @date 2020/11/14 16:23
 */
public class Producer {

    public static void main(String[] args) throws Exception {
        ConnectionFactory connectionFactory = new ConnectionFactory();

        connectionFactory.setHost("192.168.1.102");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");

        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();


        String exchange = "test_ttl_ex";
        String routingKey = "ttl.save";

        String msg = "this is producer test confirm msg";

        for (int i = 4; i >= 0; i--) {
            System.out.println(1111);
            Map<String, Object> header = new HashMap<>();
            header.put("num",i);

            AMQP.BasicProperties prop = new AMQP.BasicProperties.Builder()
                    .deliveryMode(1)
                    .headers(header)
                    .build();

            channel.basicPublish(exchange, routingKey, prop, msg.getBytes());
        }
    }
}
